package net.pulseproject.router.debuggerapp.view;

import java.awt.Dimension;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import net.pulseproject.commons.gui.IconsCache;
import net.pulseproject.commons.midi.DebuggerLogic;
import net.pulseproject.commons.midi.entity.Device;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

class DevicePanel extends JPanel {
	
	private static final long serialVersionUID = 3373632676415288881L;
	
	private static final Log LOG = LogFactory.getLog(DevicePanel.class);
	
	public DevicePanel(
			final IconsCache iconsCache,
			final JFrame parent,
			final DebuggerLogic logic,
			final Device device) {
		LOG.debug("new DevicePanel(parent, logic, device=" + device + ")");
		
		
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		
		final JLabel lblName = new JLabel("Name: " + device.getPortName());
		this.add(lblName);
		
		final JLabel lblMaxTrans = new JLabel("Max Trans: " + device.getMaxTransmitters());
		this.add(lblMaxTrans);
		final JLabel lblMaxRecv = new JLabel("Max Recv: " + device.getMaxReceivers());
		this.add(lblMaxRecv);
		
		if(device.getState().isReceiving() == true) {
			this.add(new SendPanel(iconsCache, parent, logic, device));
			final JPanel gapHack = new JPanel();
//			gapHack.setBackground(RandomUtil.randomColor());
			gapHack.setPreferredSize(new Dimension(1, 170));
			this.add(gapHack);
		}
		
		if(device.getState().isTransmitting() == true) {
			this.add(new ReceivePanel(iconsCache, parent, logic, device));
		}
	}

}
